package solution;

class Solution {
    public int maxSubArray(int[] nums) {
        int len = nums.length;

        int[] dp = new int[len + 1];
        int ret = Integer.MIN_VALUE;
        for (int i = 1; i < len + 1; i++) {
            dp[i] = Math.max(dp[i - 1] + nums[i - 1], nums[i - 1]);
            ret = Math.max(ret, dp[i]);
        }

        return ret;
    }
}